package cn.adviceclient.gui.click.neverlose.components.settings;

import cn.adviceclient.gui.click.Component;
import cn.adviceclient.features.value.BooleanSetting;
import cn.adviceclient.gui.font.Fonts;
import cn.adviceclient.utility.client.input.MouseUtil;
import cn.adviceclient.utility.render.ColorUtils;
import cn.adviceclient.utility.render.RenderUtils;
import cn.adviceclient.utility.render.RoundedUtils;
import cn.adviceclient.utility.render.animation.advanced.Animation;
import cn.adviceclient.utility.render.animation.advanced.Direction;
import cn.adviceclient.utility.render.animation.advanced.impl.DecelerateAnimation;

import java.awt.*;

import static cn.adviceclient.gui.click.neverlose.NeverLose.*;

public class BooleanComponent extends Component {
    private final BooleanSetting setting;
    private final Animation hover = new DecelerateAnimation(250,1);
    private final Animation enabled = new DecelerateAnimation(250,1);
    public BooleanComponent(BooleanSetting setting) {
        this.setting = setting;
        setHeight(24);
        enabled.setDirection(setting.get() ? Direction.FORWARDS : Direction.BACKWARDS);
    }

    @Override
    public void drawScreen(int mouseX, int mouseY) {
        enabled.setDirection(setting.get() ? Direction.FORWARDS : Direction.BACKWARDS);
        hover.setDirection(MouseUtil.isHovered2(getX() + 154,getY() + 16,20,10,mouseX,mouseY) ? Direction.FORWARDS : Direction.BACKWARDS);
            RoundedUtils.drawRound(getX() + 4, getY() + 10, 172, .5f, 4, lineColor2);

        Fonts.interSemiBold.get(17).drawString(setting.getName(),getX() + 6,getY() + 20, ColorUtils.interpolateColor2(Color.WHITE.darker().darker(),Color.WHITE, (float) enabled.getOutput()));
        RoundedUtils.drawRound(getX() + 154,getY() + 16,20,10,4,new Color(ColorUtils.interpolateColor2(new Color(ColorUtils.interpolateColor2(boolBgColor,boolBgColor2,(float) enabled.getOutput())),
                new Color(ColorUtils.interpolateColor2(boolBgColor,boolBgColor2,(float) enabled.getOutput())).brighter().brighter(), (float) hover.getOutput())));
        RenderUtils.drawCircle(getX() + 159 + 10 * (float) enabled.getOutput(),getY() + 21,0,360,5,.1f,true, ColorUtils.interpolateColor2(new Color(ColorUtils.interpolateColor2(boolCircleColor2,boolCircleColor,(float) enabled.getOutput())),
                new Color(ColorUtils.interpolateColor2(boolCircleColor.darker().darker(),boolCircleColor,(float) enabled.getOutput())).brighter().brighter(), (float) hover.getOutput()));
        super.drawScreen(mouseX, mouseY);
    }

    @Override
    public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
        if (MouseUtil.isHovered2(getX() + 154,getY() + 16,20,10,mouseX,mouseY) && mouseButton == 0){
            setting.toggle();
        }
        super.mouseClicked(mouseX, mouseY, mouseButton);
    }

    @Override
    public void mouseReleased(int mouseX, int mouseY, int state) {
        super.mouseReleased(mouseX, mouseY, state);
    }

    @Override
    public void keyTyped(char typedChar, int keyCode) {
        super.keyTyped(typedChar, keyCode);
    }
    @Override
    public boolean isVisible() {
        return setting.getVisible().get();
    }

    public BooleanSetting getSetting() {
        return setting;
    }
}
